<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Student {
            constructor(uname, age) {
                this.uname = uname;
                this.age = age;
                /*
                每创建一次对象，都会为方法开辟新的内存空间，造成资源浪费
                this.sing = function() {
                    console.log("hello");
                }
                */
            }
        }

        /*
        prototype原型对象
        每个构造函数里都会存在的一个对象
        用于共享方法，创建对象时，不用给方法开辟空间，减少内存消耗
        */
        Student.prototype.sing = () => {
            console.log("hello");
        }
        var stu1 = new Student("1");
        var stu2 = new Student("2");
        console.log(stu1.sing === stu2.sing);
        stu1.sing();
        stu2.sing();
    </script>
</body>

</html>